class Solution {
public:
    string fractionToDecimal(int numerator, int denominator) {
        
        long long x=numerator,y=denominator;
        string sFlg=x*y<0?"-":"";
        x=abs(x);
        y=abs(y);
        long long nRemain=x%y;
        x=x/y;
        if(nRemain==0){
            return sFlg+to_string(x);
        }
        string sRet=sFlg+to_string(x)+".";
        unordered_map<int,int> has;
        while(nRemain!=0){
            if(has.count(nRemain)){
                sRet.insert(has[nRemain],"(");
                sRet+=")";
                break;
            }
            has[nRemain]=sRet.size();
            nRemain*=10;
            int t=nRemain/y;
            sRet+=to_string(t);
            nRemain=nRemain%y;
        }

        return sRet;
    }
};
